package com.hibernate.learn4;

import com.hibernate.learn4.model.College;
import com.hibernate.learn4.model.Userr;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.cfg.Configuration;

// ManyToMany
public class Main {

    public static void main(String[] args) {

        Configuration configuration = new Configuration().configure("1hibernate.cfg.xml");
        configuration.addAnnotatedClass(Userr.class);
        configuration.addAnnotatedClass(College.class);

        StandardServiceRegistry registry = configuration.getStandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
        SessionFactory sessionFactory = configuration.buildSessionFactory(registry);


        College college = new College();
        college.setCollegeName("of Alexandra Rudenka");

        Userr student = new Userr();
        student.setUserrName("Katya");
        college.setStudent(student);

        Userr student2 = new Userr();
        student2.setUserrName("Vika");
        college.setStudent(student2);


        Session session = sessionFactory.openSession();
        session.beginTransaction();


        session.save(college);

        session.delete(session.find(College.class, 1));

        session.getTransaction().commit();
        sessionFactory.close();
    }

}
